



////////  //水浸传感器//////////
/*-----------------------------------------------------------------------------------------------
{"head":{"gatewayId":"gw_1C3283005078","msgId":24,"timeStamp":0,"cmd":"readAttr"},"data":{"privAddr":199,"channel":1,"nodeType":1}}
Tcp_ch1_TxData copy done
11:24:41- ETH_1 local_ktj_js Rx: len=2534
{"head":{"gatewayId":"gw_1C3283005078","replaceId":"","msgId":24,"timeStamp":1736911481,"response":"readAttr"},
"data":{"nodeType":1,"channel":1,"privAddr":199,"mac":"FFFFFFFFFFFF","name":"xwPc3_1_199","pid":"4006","totalFrame":1,"currFrame":1,"totalAttr":26,"itemCnt":26},
"attrLst":[
{"name":"almStatusLeak","lable":"状态字","class":24,"dpid":16,"val":0,"type":0},
{"name":"posiIpd","lable":"位置阻抗","class":24,"dpid":17,"val":61439,"type":0},
{"name":"detectIpd","lable":"检测阻抗","class":24,"dpid":18,"val":61439,"type":0},
{"name":"detectCurr","lable":"检测电流","class":24,"dpid":19,"val":0,"type":0},
{"name":"RGIpd","lable":"RG阻抗","class":24,"dpid":64,"val":41,"type":0},
{"name":"YBIpd","lable":"YB阻抗","class":24,"dpid":65,"val":40,"type":0},
{"name":"leakPosi","lable":"泄露位置","class":24,"dpid":67,"val":0,"type":0},
{"name":"simMode","lable":"sim工作方式","class":20,"dpid":68,"val":0,"type":0},
{"name":"thLeakIpd","lable":"泄露阻抗阈值","class":20,"dpid":69,"val":18,"type":0},
{"name":"thCurr","lable":"工作电流阈值","class":20,"dpid":70,"val":500,"type":0},
{"name":"thSensor","lable":"传感增量阈值","class":20,"dpid":71,"val":25,"type":0},
{"name":"resRate","lable":"电阻率","class":20,"dpid":80,"val":13150,"type":0},
{"name":"almDetIpd","lable":"检验阻抗低告警","class":17,"dpid":83,"val":0,"type":0},
{"name":"almCurrHi","lable":"电流高告警","class":17,"dpid":84,"val":0,"type":0},
{"name":"almCircuitIpdHi","lable":"传感回路阻抗高告警","class":17,"dpid":85,"val":0,"type":0},
{"name":"almCircuitDeltaIpdHi","lable":"回路阻抗增量高告警","class":17,"dpid":86,"val":0,"type":0},
{"name":"almEepRd","lable":"eep读错告警","class":17,"dpid":87,"val":0,"type":0},
{"name":"almEepWr","lable":"eep写错告警","class":17,"dpid":88,"val":0,"type":0},
{"name":"almEepChk","lable":"eep检验错告警","class":17,"dpid":89,"val":0,"type":0},
{"name":"flagX24c01","lable":"x24c01型号","class":17,"dpid":96,"val":0,"type":0},
{"name":"flagLowVolt","lable":"使用低压","class":17,"dpid":97,"val":0,"type":0},
{"name":"flagLowCurr","lable":"使用低电流","class":17,"dpid":98,"val":0,"type":0},
{"name":"flagDetectCycle","lable":"循环测量","class":17,"dpid":99,"val":0,"type":0},
{"name":"flagRvsPolarity","lable":"反极性方式","class":17,"dpid":100,"val":0,"type":0},
{"name":"flagAdcNoChk","lable":"adc校验禁止","class":17,"dpid":101,"val":0,"type":0},
{"name":"alarmEn","lable":"水浸报警使能","class":17,"dpid":1584,"val":0,"type":0}]}
-----------------------------------------------------------------------------------------------*/

//#include "dev_temper.h"


#ifndef __DEV_WATER_H__
#define __DEV_WATER_H__

#include "dev_module.h"
#include "iot_message.pb.h"
#include <stdint.h>
#include "iot_node.h"



#define  dev_water_max_dev_addr        (245U)      // 液位设备地址	R/W	否	配置参数	uint8_t	0~255
#define  dev_water_max_channel          (31U)      // 液位设备通道编号	R/W	否	配置参数	uint8_t	0~31



/*-----------------------------------------------------------------------------------------------
0x0530	水浸状态字	RO
0x0531	位置阻抗	RO
0x0532	检测阻抗	RO
0x0533	检测电流	RO
0x0534	RG阻抗	RO
0x0535	YB阻抗	RO
0x0536	泄露位置	RO
		
0x0602	设备通道编号	R/W
		
0x0630	水浸报警使能	R/W
0x0631	sim工作方式	R/W
0x0632	泄露阻抗阈值	R/W
0x0633	工作电流阈值	R/W
0x0634	传感增量阈值	R/W
0x0635	电阻率	R/W

									
0x0801	软件版本	RO	否	软件版本	string	最大32字节			
0x0802	硬件版本	RO	否	硬件版本	string	最大32字节			
0x0803	产品型号	RO	否	产品型号	string	最大32字节			
0x0804	生产信息	RO	否	生产信息	string	最大32字节			生产日期，生产批次等信息
0x0805	厂家信息	RO	否		string	最大32字节			生产商名称信息

-----------------------------------------------------------------------------------------*/

/////-----设备类型----
//#define   DEV_WATER_TYPE     (0xD006)     //液位传感器（D006H） 


////以下枚举的取值 需要结合 数组 dev_water_iot_id_table[dev_water_index_end]的下标进行关联的定义---同步更新----

typedef enum{

    dev_water_index_run_data_begin      = 0,    // 设备运行参数
    dev_water_index_run_data_end        = 7,     
    dev_water_index_config_data_begin   = 7,    // 设备配置参数-------------超过 8个时需要分帧处理
    dev_water_index_factory_info_begin  = 15,   // 设备出厂信息
    dev_water_index_end = 20,

} dev_water_attr_index_e;





#pragma pack(1)

//0x0530	水浸状态字	RO	是	运行参数	uint32_t	"0=正常，1=告警
typedef union{
    struct{
                                //		0	"0=无效，1=有效
        uint32_t  leak_ohm : 1;               //bit0:检验阻抗， 低于高电阻阀值 (漏水告警) 
        uint32_t  over_current: 1;        //bit1:电流大于定位电流阀值 (异常) 
        uint32_t  no_wire: 1;             //bit2:1=传感器回路高阻抗， 未检测到接线(异常) ,0： 控制器接线 (正常
        uint32_t  over_ohm: 1;            //bit3:回路阻抗/差值/平均值大于增量阀值 -----impedance
        uint32_t  read_EEPROM_error: 1;   //bit4:EEPROM读错 
        uint32_t  write_EEPROM_error: 1;  //bit5:EEPROM写错 
        uint32_t  check_EEPROM_error: 1;  //bit6:EEPROM校正错 
        uint32_t  EEPROM_X24C01A: 1;      //bit7: 1： EEPROM X24C01A型或等同的 0： EEPROM X24C01A型
        uint32_t  low_volt: 1;            //bit8:  1： 使用低压     0： 使用高压
        uint32_t  low_current: 1;         //bit9:  1： 使用低电流   0： 使用高电流
        uint32_t  loop_flag: 1;           //bit10: 1： 测量循环进行 0： 空闲
        uint32_t  reverse_polar: 1;       //bit11:  1： 反极性方式 0： 普通极性方式--reverse  polarity  
        uint32_t  adc_disable: 1;         //bit12:  1： ADC校验禁用 0： ADC校验可用
        uint32_t  res: 19;                 //其余：保留  32-13=19

    }bit;

    uint32_t value;
} dev_water_alarm_u ;


//液位传感器（D006H）的数据
///---------RO 数据--------//







 
typedef struct{

  dev_water_alarm_u  status;     // 0x0530	水浸状态字	RO
  uint16_t   position_ohm;       // Ω 0x0531	位置阻抗	RO   impedance
  uint16_t   R_khom;             // KΩ 0x0532	检测阻抗	RO   impedance
  uint16_t   current;            // 0.1μA  0x0533	检测电流	RO
  uint16_t   RG_ohm;             // Ω 0x0534	RG阻抗	   RO
  uint16_t   YB_ohm;             // Ω 0x0535	YB阻抗	   RO
  uint16_t   position_01m;       // 0.1m  0x0536	泄露位置	RO						

} dev_water_data_t;




///---------R/W	配置参数--------//
typedef struct{

    uint8_t   addr;                  //设备地址  0~255			
    uint8_t   channel;               //0x0602	设备通道编号	0~31	

    dev_water_alarm_u   alarm_enable;   //0x0630水浸报警使能	R/W"0=不启用，1=启用

    uint16_t   mode;            //          0x0631	sim工作方式	R/W
    uint16_t   leak_kohm_th;    //KΩ        0x0632	泄露阻抗阈值	R/W
    uint16_t   current_th;      //0.1μA     0x0633	工作电流阈值	R/W
    uint16_t   inc_percent_th;  //%         0x0634	传感增量阈值	R/W
    uint16_t   wire_ohm_m;      //0.001Ω/m  0x0635	电阻率	R/W  13150

} dev_water_config_t;




//---配置节点信息----------


typedef union
{
	struct{	
		
	  uint16_t online                  :1;	  //节点在线标志-----1:在线，0:离线，

	  uint16_t res                     :15;  
		
	}bit;
	
  uint16_t all;

} dev_water_node_flags_u;





// typedef enum{
//     index_1,    //
//     index_max,
// } dev_water_index_e;


//#define   WATER_NODE_NUM_MAX    (255U)  

#define   WATER_NODE_NUM_MAX    (NODE_NUM_MAX)     ///与配置节点总数相关-----



typedef struct{
    dev_water_data_t         data;
    dev_water_config_t       config;
    dev_attr_com_info_t      info;

    dev_water_node_flags_u  flags;
   // char   dev_name_str[32];   
} dev_water_attr_t;


#pragma pack()


extern const  uint16_t  dev_water_iot_id_table[dev_water_index_end];



/**
 * @brief 
 * 
 */
void dev_water_param_init(void);

uint8_t dev_water_add_obj(uint8_t idx,uint8_t channel,uint8_t addr);


/**
 * @brief 
 * 
 * @param in idx 
 * @return dev_water_attr_t ==NULL 查询出错,   !NULL 查询ok
 */
dev_water_attr_t*  dev_water_get_obj(uint8_t idx) ;  //dev_water_attr_get


/**
 * @brief dev_water_set_obj() 赋值节点数据
 * 
 * @param in idx
 * @param in p_attr
 * @return 0=失败，1=成功 
 */
uint8_t  dev_water_set_obj(uint8_t idx,dev_water_attr_t* p_attr )  ;



  //  dev_water_index_run_data_begin      = 0,    // 设备运行参数
  //  dev_water_index_config_data_begin   = 3,    // 设备配置参数
/**
 * @brief 根据下标，获取iot_id 的编号
 * 
 * @param idx 
 */
uint16_t  dev_water_get_iot_id(uint8_t idx);


/**
 * @brief 
 * 
 * @param attr_id 
 * @param attr_out 
 */
void dev_water_get_attr(uint8_t idx,uint16_t attr_id, IotModel* attr_out);


/**
 * @brief 
 * 
 * @param attr_in 
 * @return uint8_t 
 */
uint8_t dev_water_set_attr(uint8_t idx,IotModel* attr_in);


void dev_water_test_tick_min(uint8_t idx);

////刷新节点运行数据
void dev_water_update_tick_min(uint8_t idx,int8_t temper ,uint32_t dev_water );

void dev_water_obj_update(uint8_t idx,dev_water_attr_t* pliq_in  );




#endif //------__DEV_WATER_H__


























